{% if environment == 'production' %}
FROM debian:bookworm AS node-builder

{% include 'nodejs-install.j2' %}

RUN mkdir -p /app
WORKDIR /app

COPY package.json \
    package-lock.json \
    webpack.prod.js \
    webpack.common.js \
    tsconfig.json \
    /app/
RUN npm install

COPY ./static/sass/*.scss /app/static/sass/
COPY ./static/src/ /app/static/src/
RUN npm run build

{% endif %}
{% include 'Dockerfile.base.j2' %}

COPY requirements/requirements.txt /tmp/requirements.txt
{% if disable_cache_mounts %}
RUN \
{% else %}
RUN --mount=type=cache,target=/root/.cache/pip \
{% endif %}
    pip3 install -r /tmp/requirements.txt --break-system-packages

RUN mkdir -p /usr/src/app
COPY . /usr/src/app/
WORKDIR /usr/src/app

{% if environment == 'production' %}
COPY --from=node-builder \
    /app/static/dist/ \
    /usr/src/app/static/dist/
{% else %}
{% include 'nodejs-install.j2' %}
{% endif %}

ENV GIT_HASH={{ git_hash }}
ENV GIT_SHORT_HASH={{ git_short_hash }}
ENV GIT_BRANCH={{ git_branch }}
ENV DEVICE_TYPE={{ board }}

CMD ["bash", "bin/start_server.sh"]
